<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
Style Guide
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial009.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial011.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H1 CLASS="chapter"><A NAME="htoc89">Appendix&nbsp;A</A>&nbsp;&nbsp;Style Guide</H1><UL>
<LI><A HREF="tutorial010.html#toc48">Style rules</A>
<LI><A HREF="tutorial010.html#toc49">Module structure</A>
<LI><A HREF="tutorial010.html#toc50">Predicate definition</A>
</UL>

<A NAME="styleguide"></A>
<A NAME="toc48"></A>
<H2 CLASS="section"><A NAME="htoc90">A.1</A>&nbsp;&nbsp;Style rules</H2>
<OL CLASS="enumerate" type=1><LI CLASS="li-enumerate">
There is one directory containing all code and its documentation (using sub-directories).
<LI CLASS="li-enumerate">Filenames<A NAME="@default273"></A> are of form [a-z][a-z_]+ with extension .ecl .
<LI CLASS="li-enumerate">One file per module, one module per file.
<LI CLASS="li-enumerate">Each module is documented with comment directives.
<LI CLASS="li-enumerate">All required interfaces are defined in separate spec files which are included in the source with a <I>comment include</I> directive. This helps to separate specification and implementation code.
<LI CLASS="li-enumerate">The actual data of the problem is loaded dynamically from the Java interface; for stand-alone testing data files from the data directory are included in the correct modules.
<LI CLASS="li-enumerate">The file name is equal to the module name.
<LI CLASS="li-enumerate">Predicate names<A NAME="@default274"></A> are of form [a-z][a-z_]*[0-9]* . Underscores are used to separate words. Digits should only be used at the end of the name. Words should be English.
<LI CLASS="li-enumerate">Variable names<A NAME="@default275"></A> are of form [A-Z_][a-zA-Z]*[0-9]* . Separate words star with capital letters. Words should be English. The plural should be used for lists and other collections. Digits should only be used at the end to distinguish different versions of the same conceptual thing.
<LI CLASS="li-enumerate">The code should not contain singleton variables<A NAME="@default276"></A>, unless their names start with _. The final program may not generate singleton warnings.
<LI CLASS="li-enumerate">Each exported predicate is documented with a comment directive<A NAME="@default277"></A>.
<LI CLASS="li-enumerate">Clauses for a predicate must be consecutive.
<LI CLASS="li-enumerate">Base clauses should be stated before recursive cases.
<LI CLASS="li-enumerate">Input arguments should be placed before output arguments.
<LI CLASS="li-enumerate">Predicates which are not exported should be documented with a single line comment. It is possible to use comment directives instead.
<LI CLASS="li-enumerate">The sequence of predicates in a file is top-down with a (possibly empty) utility section at the end.
<LI CLASS="li-enumerate">All structures are defined in one file (e.g. flow_structures.ecl) and are documented with comment directives.
<LI CLASS="li-enumerate">Terms should not be used; instead use named structures<A NAME="@default278"></A>.
<LI CLASS="li-enumerate">When possible, use do loops instead of recursion.
<LI CLASS="li-enumerate">When possible, use separate predicates instead of disjunction<A NAME="@default279"></A> or if-then-else.
<LI CLASS="li-enumerate">There should be no nested if-then-else<A NAME="@default280"></A> construct in the code.
<LI CLASS="li-enumerate">All input data should be converted into structures at the beginning of the program; there should be no direct access to the data afterwards. 
<LI CLASS="li-enumerate">All numeric constants<A NAME="@default281"></A> should be parametrized via facts. There should be no numeric values (other than 0 and 1) in rules.
<LI CLASS="li-enumerate">The final code should not use failure-loops<A NAME="@default282"></A>; they are acceptable for debugging or testing purposes.
<LI CLASS="li-enumerate">Cuts (!) <A NAME="@default283"></A> should be inserted only to eliminate clearly defined choice points.
<LI CLASS="li-enumerate">The final code may not contain open choice points, except for alternative solutions that still can be explored. This is verified with the tracer tool in the debugger.
<LI CLASS="li-enumerate">Customizable data facts should always be at the end of a file; their use is deprecated.
<LI CLASS="li-enumerate">The predicate member/2<A NAME="@default284"></A> should only be used where backtracking is required; otherwise use memberchk/2<A NAME="@default285"></A> to avoid hidden choice points.
<LI CLASS="li-enumerate">The final code may not contain dead code<A NAME="@default286"></A> except in the file/module unsupported.ecl. This file should contain all program pieces which are kept for information/debugging, but which are not part of the deliverable.
<LI CLASS="li-enumerate">The test set(s) should exercise 100 percent of the final code. Conformity is checked with the line coverage profiler.
<LI CLASS="li-enumerate">Explicit unification (=/2) should be replaced with unification inside terms where possible.
<LI CLASS="li-enumerate">There is a top-level file (document.ecl) which can be used to generated all on-line documentation automatically.
<LI CLASS="li-enumerate">Don't use ','/2 to make tuples.
<LI CLASS="li-enumerate">Don't use lists to make tuples.
<LI CLASS="li-enumerate">Avoid append/3 where possible, use accumulators instead.
</OL>
<A NAME="toc49"></A>
<H2 CLASS="section"><A NAME="htoc91">A.2</A>&nbsp;&nbsp;Module structure</H2>
The general form of a module is:
<OL CLASS="enumerate" type=1><LI CLASS="li-enumerate">
module definition
<LI CLASS="li-enumerate">module comment or inclusion of a spec file
<LI CLASS="li-enumerate">exported/reexported predicates
<LI CLASS="li-enumerate">used modules
<LI CLASS="li-enumerate">used libraries
<LI CLASS="li-enumerate">local variable definitions 
<LI CLASS="li-enumerate">other global operations and settings
<LI CLASS="li-enumerate">predicate definitions
</OL>
<A NAME="toc50"></A>
<H2 CLASS="section"><A NAME="htoc92">A.3</A>&nbsp;&nbsp;Predicate definition</H2>
The general form of a predicate definition is:
<OL CLASS="enumerate" type=1><LI CLASS="li-enumerate">
predicate comment directive
<LI CLASS="li-enumerate">mode declaration
<LI CLASS="li-enumerate">predicate body
</OL>
<HR>
<A HREF="tutorial009.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial011.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
